<?php
/**
 * White Page Web Crawling
 */

use Fox\Dao\SqlFragment;
use Fox\Common\Localization\SubRegion;
use Fox\Common\Localization\City;
use Fox\Common\Localization\City\Street;
use Fox\Html\CheckBox;
use Fox\Html\Input;
use Fox\Html\Screen;

set_time_limit(Xview::TIMEOUT_VERY_LONG);

$screen = new Screen("extract","extract");
$block = new Block("b","Extract Source Files");
$block->add(new TextArea("postal_code",true));
$block->add(new CheckBox("commit"));
$block->add(new Input("dbcnt",true,1));
$screen->add($block);

if($screen->posted())
{
	$grid = new Fox\Grid("gResult");
	$grid->setFieldCat(array("cityname","postal_code","status","nbstreets","nbdownloaded","msgtx"));
	$inputs = $screen->get();
	if(!Xview::instance()->errors())
	{
		$query = \Fox\Dao::infos(City::className())->handle()->createQueryBuilder();
		$query->select('c.fullname','c.postal_code','s.status','COUNT(*)')
				->from('cities','c')
				->innerJoin('c','city_streets','s','on c.cityid = s.cityid')
				->groupBy('c.fullname','c.postal_code','s.status');
				
		$fragments[] = new SqlFragment("c.disable = ?",array(0));	
		$fragment = SqlFragment::combine($fragments);
		$fragment->pushIn($query)->execute()->fetchAll(\PDO::FETCH_ASSOC);
	}
}
$screen->display();

if(isset($grid))
	echo $grid->display();